import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Demo2 {
    public static void main(String[] args) {
        try(Writer writer =new FileWriter("data.txt")) {
            writer.write("你好，世界");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main5(String[] args) {
        try(Reader reader =new FileReader("data.txt")) {
            while (true){
                char[] arrays =new char[1024];
                int ret =reader.read(arrays);
                if (ret ==-1){
                    break;
                }
                for (int i=0;i<ret;i++){
                    System.out.println(arrays[i]);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main4(String[] args) throws FileNotFoundException {
        try(Reader reader =new FileReader("data.txt")) {
            while (true){
                int ret =reader.read();
                if (ret ==-1){
                    break;
                }
                System.out.printf("%c\n",(char)ret);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main3(String[] args) throws FileNotFoundException {
        try (OutputStream outputStream = new FileOutputStream("data.txt",true)) {
            outputStream.write(97);
            outputStream.write(98);
            outputStream.write(99);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main2(String[] args) {
        try (InputStream inputStream =new FileInputStream("data.txt")){
          while (true){
              byte[] bytes = new byte[1024];
              int ret =inputStream.read(bytes);
              if (ret==-1){
                  break;
              }
              for(int i=0;i<ret;i++){
                  System.out.printf("0x%x\n",bytes[i]);
              }

          }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main1(String[] args) throws FileNotFoundException {
        try (InputStream inputStream =new FileInputStream("data.txt")){
          while (true){
              int ret =inputStream.read();
              if (ret==-1){
                  break;
              }
              System.out.printf("0x%x\n",ret);
          }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
